import Vue from 'vue'
import Vuex from 'vuex'
//配置导入
import config from "../config.js";

Vue.use(Vuex)
    //环境
console.log(config.serverState ? '正式环境' : '测试环境')

const store = new Vuex.Store({
    state: {
        authKey: null,
        base_url: config.serverState ? config.server_url + "/api/v1/mini/index.aspx" : config.debug_url + "/api/v1/mini/index.aspx",
		shopping_url: config.serverState ? config.server_url + "/api/v1/shop/index.aspx" : config.debug_url + "/api/v1/shop/index.aspx",
		vote_url: config.serverState ? config.server_url + "/api/v1/vote/index.aspx" : config.debug_url + "/api/v1/vote/index.aspx",
		currTime:0,
		examState:false
    },
    mutations: {
        login(state, userinfo) {
            //console.log(userinfo)
            // state.hasLogin = true
            // state.userinfo = userinfo
            // uni.setStorageSync("authUserInfo", userinfo)
        },
        logout(state) {
            // state.hasLogin = false
            // state.openid = null
            // state.userinfo = {}
            // state.shopcartnum = 0
            // state.communityinfo = null
            // uni.removeStorageSync('authUserInfo')
        },
		setCurrTime(state, currTime){
			state.currTime = currTime
		},
		setExamState(state, examState){
			state.examState = examState
		}
    },
    actions: {
        getIndexInfoList: async function({ commit, state }) {
            return await new Promise((resolve, reject) => {
                if (state.homelist) {
                    resolve(state.homelist)
                } else {
                    resolve("error")
                }
            })
        },
		getSystemInfo: async function({ commit, state }){
			return await new Promise((resolve, reject) => {
			   switch(uni.getSystemInfoSync().platform){
			       case 'android':
			          resolve("android")
			          break;
			       case 'ios':
			          resolve("ios")
			          break;
			       default:
			          console.log('other')
			          break;
			   }
			})
			
		}
    },
    modules: {}
})

export default store